package com.quanyue.haircut.shop.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Principal;
import com.quanyue.auto.web.Scope;
import com.quanyue.haircut.domain.constant.UserRole;
import com.quanyue.haircut.domain.entity.SystemNotice;
import com.quanyue.haircut.shop.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Api(tags = "系统公告")
@RestController
@RequestMapping("/api")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @ApiOperation("添加公告")
    @Scope(role = UserRole.MANAGER)
    @PostMapping("/notice")
    public ServiceResult <Boolean> addNotice(@RequestBody SystemNotice content, Principal principal) {
        content.setMerchantNo(principal.getMerchantNo());
        noticeService.addNotice(content);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation("查看公告")
    @GetMapping("/notice")
    public ServiceResult <List <SystemNotice>> selectNotice(@ApiIgnore Principal principal) {
        return ServiceResult.success(noticeService.findNotice(principal.getMerchantNo()));
    }

    @ApiOperation("删除")
    @Scope(role = UserRole.MANAGER)
    @DeleteMapping("/notice")
    public ServiceResult <Boolean> signNotice(@RequestParam Integer noticeId) {
        noticeService.deleteNotice(noticeId);
        return ServiceResult.SUCCESS;
    }
}
